<script setup lang="ts">
import type { CategoryItem } from '@/types/home'

// 定义 props 接收数据
defineProps<{
  list: CategoryItem[]
}>()
const onClickCategoryItem = (href_url: string, id: string) => {
  console.log('url:', href_url)
  console.log('id:', id)
  if (
    href_url !== '/pages/compose/united' &&
    href_url !== '/pages/compose/original' &&
    href_url !== '/pages/upload/step_two_revisable_paper_list' &&
    href_url !== '/pages/upload/upload_guide_paper' &&
    href_url !== '/pages/upload/step_one_select_question_video' &&
    href_url !== '/pages/handpicked/index' &&
    href_url !== '/pages/goods/goods'
  ) {
    uni.switchTab({ url: href_url })
  } else {
    uni.navigateTo({ url: href_url })
  }
}
</script>

<template>
  <view class="category">
    <view class="category-item" hover-class="none" v-for="item in list" :key="item.href_url"
      @tap="onClickCategoryItem(item.href_url, item.id)">
      <image class="icon" :src="item.icon"></image>
      <text class="text">{{ item.name }}</text>
    </view>
  </view>
</template>

<style lang="scss">
@import '../styles/category.scss';
</style>
